<?php
	echo CHtml::cssFile(Yii::app()->baseUrl.'/assets/css/uploader.css');
?>
<div class="content">
	
	<div class="bar">
    	<div style="float:left">
        	<?php
				echo CHtml::beginForm(
					array(
						$this->controller_id."/upload",
						"current_folder" => $current_folder
					),
					"post",
					array('enctype'=>'multipart/form-data')
				);
					echo "File Upload ";
					echo CHtml::fileField("file","", array("size"=>50));
					echo " ";
					echo CHtml::submitButton("Upload");
				echo CHtml::endForm();
			?>
            
        </div>
        
        <div style="float:left;">
        	<?php
				
				echo CHtml::beginForm(
					array(
						$this->controller_id."/create_folder",
						"current_folder" => $current_folder
					),
					"post"
				);
					echo "&nbsp;&nbsp;|&nbsp;&nbsp;";
					echo "Tên thư mục ";
					echo CHtml::textField("folder_name", "", array("size"=>30));
					echo " " ;
					echo CHtml::submitButton("Tạo thư mục");
				echo CHtml::endForm();
			?>
        </div>
		
    </div>
    

        <div class="path">
        	<?php
				$paths = explode("/", $current_folder);
				echo CHtml::image(
					Yii::app()->baseUrl."/assets/icon/dir.png",
					"",
					array("align"=>"top")
				);
				echo  " ";
				foreach($paths as $path)
				{
					$str = substr($current_folder,0,strpos($current_folder,$path)+strlen($path));
					echo CHtml::link(
						$path,
						array(	
							$this->controller_id."/view",
							"current_folder" => urlencode($str)
						),
						array("class"=>"link_folder")
					);
					echo CHtml::image(
						Yii::app()->baseUrl."/assets/icon/icon_break.png",
						"",
						array("align"=>"absmiddle")
					);
				}
			?>
        </div><!-- end path -->
        
         <div class="body">
    <?php
        if(count($folders))
        {
            foreach($folders as $folder)
            {
                echo "<div class='wrapper_item'>";
                
                    echo "<div class='item'>";
						echo "<div style='height:16px; text-align:right;'>";
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-tick.png"),
								array($this->controller_id."/rename_folder"),
								array("title"=>"Rename")
							);
							echo " ";
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-remove.png"),
								array(
									$this->controller_id."/delete_folder",
									"current_folder" => urlencode($current_folder),
									"folder_name" => $folder
								),
								array("title"=>"Delete")
							);
						echo "</div>";
                        echo "<div class='image_folder'>";
                            echo CHtml::link(
								CHtml::image($this->webroot."/assets/icon/icon_folder.png"),
								array(
									$this->controller_id."/view/",
									"current_folder" => urlencode($current_folder."/".$folder)
								)
							);
                        echo "</div>";
                        echo "<div class='text'>";
                            echo CHtml::link(
								$folder,
								array(
									$this->controller_id."/view/",
									"current_folder" => urlencode($current_folder."/".$folder)
								),
								array("class"=>"link_folder")
							);
                        echo "</div>";
                    echo "</div>";
                    
                echo "</div>";
            }
        }
        
        
        if (count($files))
        {
            $icon_file = array(
                ".jpg" => "icon-48-image.png",
                ".png" => "icon-48-image.png",
                ".gif" => "icon-48-image.png",
				".bmp" => "icon-48-image.png",
                
                ".doc" => "icon_doc.png",
                ".docx" => "icon_doc.png",
                
                ".xls" => "icon_xls.png",
                ".xlsx" => "icon_xls.png",
                
                ".ppt" => "icon_ppt.png",
                ".pptx" => "icon_ppt.png",
                
                ".pdf" => "icon_pdf.png",
                
            );
            foreach($files as $file)
            {
                echo "<div class='wrapper_item'>";
                
                    echo "<div class='item'>";
						echo "<div style='height:16px; text-align:right;'>";
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-tick.png"),
								array($this->controller_id."/rename_file"),
								array("title"=>"Rename")
							);
							echo " ";
							echo CHtml::link(
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-remove.png"),
								array(
									$this->controller_id."/delete_file",
									"current_folder" => urlencode($current_folder),
									"file_name" => $file["name"]
								),
								array("title"=>"Delete")
							);
						echo "</div>";
						
                            if ($file["type"] == ".jpg" || 
                                $file["type"] == ".png" || 
                                $file["type"] == ".gif" || 
								$file["type"] == ".bmp"
                            )
                            {
								echo "<div class='image'>";
                                echo CHtml::image(
                                    $this->webroot."/../".$current_folder."/".$file["name"],
                                    "",
                                    array(
										"style"=>"width:80px; height:55px;border:1px solid #ddd;",
										"title"=>$file["name"]	
									)
                                );
								echo "</div>";
                            }
                            else
                            {
								echo "<div class='image_file'>";
                                echo CHtml::image(
                                    $this->webroot."/assets/icon/".$icon_file[$file["type"]],
                                    "",
                                    array(
										"title"=>$file["name"]
									)
                                );
								echo "</div>";
							}
                       
                        echo "<div class='text'>";
                            if (strlen($file["name"]) > 15)
                                echo substr($file["name"],0,12) . $file["type"];
                            else
                                echo $file["name"];
                        echo "</div>";
                    echo "</div>";// end item
                    
                echo "</div>";
            }
        }
        
        
    ?>
         </div><!-- end body -->

        
   
</div><!-- end div content -->

<script language="javascript">

$(document).ready(function(){
	
});

</script>
